#include "src/Terrain.h"
#include <stdlib.h>
#include <stdio.h>

Terrain * initTerrain(Terrain * Ter)
{
    Ter = (Terrain *)malloc(sizeof(Terrain));

printf("là 2-2-0\n");
char premier_Terrain[15][20] = {
        "~###################",
		"~...................",
		"~...................",
		"~...................",
		"~...................",
		"~...................",
		"~...................",
		"~...................",
		"~...................",
		"~...................",
		"~...................",
		"~...................",
		"~...................",
		"~...................",
        "~###################"
};printf("là 2-2-0-1\n");
printf(" %d \n", Ter->dimX);
    Ter->dimY = 15;
    printf("là 2-2-0-2\n");
    Ter->dimX = 20;
    printf("là 2-2-0-3\n");
    printf(" %d \n", Ter->dimX);
    printf(" %d \n", Ter->dimY);
    printf(" %c \n", premier_Terrain[2][3]);
     printf(" %c \n", premier_Terrain[3][2]);

    int i, j;
//    int d, a;
    printf("là 2-2-1\n");

    Ter->tab = (char **)malloc(sizeof(char *)*Ter->dimY);
    printf("là 2-2-2\n");
    	for (j=0; j<Ter->dimY; j++)

		Ter->tab[j] = (char *)malloc(sizeof(char)*Ter->dimX);

	for(j=0;j<Ter->dimY;++j)
		for(i=0;i<Ter->dimX;++i)
			Ter->tab[j][i] = premier_Terrain[j][i];







			printf(" %d \n", Ter->dimX);
			printf(" %d \n", Ter->dimY);

			return Ter;

}


void libereTerrain(Terrain * Ter)
{
    Ter->dimX=0;
    Ter->dimY=0;
    Ter->tab = NULL;
}

//rajouter le cas pour les zombies
int deplacementPersoValide(const int x, const int y,const Terrain * Ter)
{
	if (x>=0 && x<Ter->dimX && y>=0 && y<Ter->dimY && Ter->tab[y][x]!='#')
		return 1;
	else
		return 0;
}

const char terrainGetCharCoord (const Terrain *Ter, int x,int y)
{
    return Ter->tab[x][y];
}

void terrainSetChatCoord(Terrain * Ter, int x, int y, char a)
{
    Ter->tab[x][y]=a;
}

// on verra plus tard
void genererTerrain(Terrain * Ter)
{


}

// rajouter le cas avec les zombies
int deplacementProjectileValide (Terrain * Ter, int x, int y)
{
    if (x>=0 && x<Ter->dimX && y>=0 && y<Ter->dimY && Ter->tab[y][x]!='#')
		return 1;
	else
		return 0;
}

// rajouter le cas avec les persos/projectile
int deplacementZombieValide (Terrain * Ter, int x, int y)
{
    if (x>=0 && x<Ter->dimX && y>=0 && y<Ter->dimY && Ter->tab[y][x]!='#')
		return 1;
	else
		return 0;
}

